package com.ruoyi.web.controller.blog;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BlogType;
import com.ruoyi.system.service.IBlogTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 博客类目Controller
 *
 * @author ruoyi
 * @date 2022-07-31
 */
@Api("博客类目管理")
@RestController
@RequestMapping("/system/type")
public class BlogTypeController extends BaseController {
    @Autowired
    private IBlogTypeService blogTypeService;

    /**
     * 查询博客类目列表
     */
    @ApiOperation("查询博客类目列表")
    @GetMapping("/list")
    public TableDataInfo list(BlogType blogType) {
        startPage();
        List<BlogType> list = blogTypeService.selectBlogTypeList(blogType);
        return getDataTable(list);
    }


    /**
     * 获取博客类目详细信息
     */
    @ApiOperation("获取博客类目详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(blogTypeService.selectBlogTypeById(id));
    }

    /**
     * 新增博客类目
     */
    @ApiOperation("新增博客类目")
    @Log(title = "博客类目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogType blogType) {
        return toAjax(blogTypeService.insertBlogType(blogType));
    }

    /**
     * 修改博客类目
     */
    @ApiOperation("修改博客类目")
    @Log(title = "博客类目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogType blogType) {
        return toAjax(blogTypeService.updateBlogType(blogType));
    }

    /**
     * 删除博客类目
     */
    @ApiOperation("删除博客类目")
    @Log(title = "博客类目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(blogTypeService.deleteBlogTypeByIds(ids));
    }
}
